package 题目集.贪心.排序模拟;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
//https://pintia.cn/problem-sets/1734589674052866048/exam/problems/1734589708576198657?type=7&page=0
public class 点赞狂魔 {
    public static void main(String[] args) throws IOException {
        BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
        PriorityQueue<Node> queue=new PriorityQueue<>((o1, o2) -> {
            if (o1.count== o2.count){
                return o2.total- o1.total;
            }
            return o1.count- o2.count;
        });
        int n = Integer.parseInt(in.readLine());
        String[] read=null;
        while (n-- > 0) {
            read=in.readLine().split(" ");
            Set<String> set = new HashSet<>();
            int k = Integer.parseInt(read[1]);
            for (int i = 2; i < read.length; i++) {
                set.add(read[i]);
            }
            if (queue.size()<3){
                queue.add(new Node(read[0],set.size(),k));
                continue;
            }
            if (queue.peek().count<set.size()){
                queue.poll();
                queue.add(new Node(read[0], set.size(),k));
            }
        }
        LinkedList<String> link=new LinkedList<>();
        for (int i = 0; i < 3; i++) {
            if (!queue.isEmpty()) {
                link.addFirst(queue.poll().name);
            }else {
                link.add("-");
            }
        }
        StringBuilder sb=new StringBuilder();
        for (String s : link) {
            sb.append(s).append(" ");
        }
        System.out.println(sb.substring(0,sb.length()-1));
    }
    static class Node{
        String name;
        int count;
        int total;

        public Node(String name, int count, int total) {
            this.name = name;
            this.count = count;
            this.total = total;
        }
    }
}

